package com.neusoft.service.impl;

import com.neusoft.core.Business;
import com.neusoft.feign.UserFeignClient;
import com.neusoft.mapper.BusinessMapper;
import com.neusoft.mapper.UserMapper;
import com.neusoft.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserFeignClient userFeignClient;
    @Override
    public List<Business> listBusinessByOrderTypeId(Integer orderTypeId) {
        return businessMapper.listBusinessByOrderTypeId(orderTypeId);
    }

    @Override
    public Business getBusinessById(Integer businessId) {
        return businessMapper.getBusinessById(businessId);
    }
    @Override
    public List<Business> listBusinessByKeyWord(String keyWord) {
        System.out.println(keyWord);
        return businessMapper.listBusinessByKeyWord(keyWord);
    }

    @Override
    public Integer saveBusiness(String userId, String password, String businessName) {
//        //User foundUser = userMapper.getUserByIdByPass(userId);
//        User foundUser = userFeignClient.getUserByIdByPass(userId, password).getResult();
//        if (foundUser != null && PasswordEncoderUtil.matches(password, foundUser.getPassword()) == true) {
            businessMapper.saveBusiness(businessName,userId);
            Integer businessId = 10000 + businessMapper.getBusinessesNumber();
            userMapper.updateBusinessIdByUserId(userId,businessId);
            //userMapper.updateUserTypeByUserId(userId, businessId);
//            userFeignClient.updateUserTypeByUserId(new User(userId, businessId));
            return businessId;
//        }
//        return -1;
    }

    @Override
    public int updateBusiness(Business business) {
        return businessMapper.updateBusiness(business);
    }

    @Override
    public int updateBusinessImg(String businessImg, String businessId) {
        return businessMapper.updateBusinessImg(businessImg, businessId);
    }
}
